/*
 * ./main.c
 * Copyright (C) 2009 lameire alexis
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "gestion_connection.h"
#include "fonction_connection.h"
#include "special_opt.h"
#include "trie_commandes.h"

int main(int argc, char **argv)
{
	irc_session_t *session;
	irc_callbacks_t evenement;
	config *configuration;
	donnee_de_control jeux;
	int erreur = 0;

	//analyse des arguments
	if (argc != 0)
	{
		parse_args(argc, argv);
	}
	//initialisation de l'internationalisation
	setlocale(LC_ALL, "");
	bindtextdomain("d7c", "./");
	textdomain("d7c");

	memset(&evenement, 0, sizeof(irc_callbacks_t));
	memset(&jeux, 0, sizeof(donnee_de_control));

	srand(time(NULL));

	evenement.event_connect = connection_du_bot;
	evenement.event_join = join_du_bot;
	evenement.event_channel = algo_bot;
	evenement.event_privmsg = algo_bot;
	evenement.event_notice = algo_bot;
	evenement.event_numeric = lister_pseudo;

	session = irc_create_session(&evenement);
	irc_option_set(session, 1 << 2);

	/* recuperation de la configuration */
	configuration = ouvrir_fichier_de_conf();
	jeux.commandes = init_commandes(configuration->token, &(jeux.nb_commandes));
	jeux.config_prog = configuration;

	irc_set_ctx(session, &jeux);

	printf(_("DEBUG : Session : %p\n"), session);
	erreur = irc_connect(session, jeux.config_prog->server,	//serveur
			     jeux.config_prog->port,	//port
			     NULL,	//password
			     jeux.config_prog->pseudo,	//nom
			     _("no_human"), _("Décrypte le code, le bot !"));
	printf(_("DEBUG : Code d'erreur %d\n"), erreur);
	erreur = irc_run(session);
	printf(_("DEBUG : Code d'erreur %d\n"), erreur);
	return 1;
}
